//
//  MainViewController.swift
//  Sina Weibo
//
//  Created by Gin on 16/1/11.
//  Copyright © 2016年 Gin. All rights reserved.
//

import UIKit
////导入Snapkit框架
//import SnapKit

class MainViewController: UITabBarController {

    //MARK:按钮的监听事件.
    @objc private func plusBtnDidClick() {
        print(__FUNCTION__)
    }
    //
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //系统的tabbar是只读属性,无法直接访问,但是可以通过kvc来访问.
        let mainTabBar=MainTabBar()
        //
        setValue(mainTabBar, forKey: "tabBar")
        //给按钮添加监听事件.
        mainTabBar.plusBtn.addTarget(self, action: "plusBtnDidClick", forControlEvents: .TouchUpInside)
        //根控制器入口.
        addChildViewControllers()
    }

    
    //添加所有子视图控制器的方法.
    private func addChildViewControllers() {
        addChildViewController(HomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(MessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(DiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(ProfileTableViewController(), imageName: "tabbar_profile", title: "我")
    }
    //添加单个子视图控制器的方法.???
    func addChildViewController(vc:UIViewController,imageName:String,title:String){
        vc.title=title;
        vc.tabBarItem.image=UIImage(named: imageName)
        tabBar.tintColor=UIColor.orangeColor()
        let nav=UINavigationController(rootViewController: vc)
        //注意这个方法是系统的,并不是当前自定义的.
        addChildViewController(nav)
    }
}
